#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
char s[maxn];
long long flag[maxn];
long long flag_[maxn];
int main()
{
	long long t;
	cin>>t;
	while(t--)
	{
		long long n,x;
		cin>>n>>x;
		cin>>s;
		int len = strlen(s);
		long long  cnt0 = 0;
		long long cnt1 = 0;
		long long cnt0_ = 0;
		long long cnt1_ = 0;
		for(int i = 0,j=len-1;i<len;i++,j--)
		{
			
			if(s[i]=='0') cnt0++;
			else cnt1++;
			if(s[j]=='0') cnt0_++;
			else cnt1_++;
			flag[i] = cnt0-cnt1;
			flag_[i] = cnt0_-cnt1_;
		}
		long long m = cnt0-cnt1;
		if(m*x<0) printf("0\n");
		else if(m==x&&m==0) printf("-1\n");
		else 
		{
			long long ans = 0;
			long long f = x%m;
			if(f==0) ans = 1;
			for(int i = 0;i<len;i++)
			{
				if(flag[i]==f )ans++;
				if(flag_[i]==f)ans++;
			}
			cout<<ans<<endl;
		}
	}
}
